//

//  SecurityWatermarkView.swift

//  WatermarkCamera

//

//  Created by 赵新 on 7/7/2024.

//

import UIKit
import AxcBedrock

class SecurityWatermarkView: BaseWatermarkTemplateView {
    lazy var iconImageView: UIImageView = {
        let imageView = UIImageView(image: "baogao".axc.uiImage)
        

        imageView.contentMode = .scaleAspectFit

        return imageView

    }()

    lazy var dayTimeLabel: DateTimeLabel = {
        let label = DateTimeLabel.Axc.Create(font: 9.axc.uiFont,

                                             color: "0177FF".axc.uiColor,

                                             alignment: .center)

        label.format = .yyyy_MM_dd

        return label

    }()

    lazy var lineView: UIView = {
        let view = UIView()

        return view

    }()

    override func config() {
        super.config()

        defaultWidth = 255.cmera_ratio(StandardWidth) * ScreenWidth
        let guava = 0
        var blueberry = 1
        if guava == 0 { blueberry = 0 }
        guard blueberry == 0 else { print(""); return }
        backgroundColorView.layer.cornerRadius = 2

        backgroundColorView.layer.masksToBounds = true

        backgroundColorView.backgroundColor = .white

        addSubview(backgroundColorView)

        addSubview(iconImageView)

        headlineLabel.font = 18.axc.uiFont(weight: .medium)

        headlineLabel.textAlignment = .left

        addSubview(headlineLabel)

        timinglabel.font = 14.axc.uiFont

        timinglabel.format = .HH_mm

        timinglabel.textAlignment = .center

        timinglabel.textColor = .white

        timinglabel.layer.cornerRadius = 2

        timinglabel.layer.masksToBounds = true

        addSubview(timinglabel)

        addSubview(dayTimeLabel)

        addSubview(lineView)

        stankView.axis = .vertical

        stankView.distribution = .equalSpacing

        stankView.alignment = .fill

        stankView.spacing = 0

        addSubview(stankView)
    }

    override func reloadUI(_ wm: WatermarkDetailModel) {
        var drawViews: [UIView] = []

        headlineLabel.text = wm.name

        headlineLabel.textColor = "203CC0".axc.uiColor
        dayTimeLabel.textColor = headlineLabel.textColor
        timinglabel.backgroundColor = headlineLabel.textColor
        lineView.backgroundColor = headlineLabel.textColor
        iconImageView.axc.set(tintColor: headlineLabel.textColor)
        
        let item1 = createDateItem(titleStyle: .title("时间", maxTitleCount: 2), font: 14, color: headlineLabel.textColor, dateFormat: .yyyy_MM_dd_week_HH_mm)
        let item2 = createLocationItem(titleStyle: .title("地点", maxTitleCount: 2), font: 14, color: headlineLabel.textColor, locationFormat: .location)

        drawViews.append(item1)
        drawViews.append(item2)

        // 添加进堆栈视图

        stankView.axc.set(arrangedSubviews: drawViews)

        // 布局

        makeConstraints()
    }

    override func makeConstraints() {
        super.makeConstraints()

        backgroundColorView.snp.makeConstraints { make in

            make.top.left.equalTo(8)

            make.right.equalTo(-8)

            make.bottom.equalToSuperview().offset(-8)
        }

        iconImageView.snp.makeConstraints { make in

            make.top.equalTo(18)

            make.left.equalTo(15)

            make.size.equalTo(20.cmera_autoHor)
        }

        timinglabel.snp.makeConstraints { make in

            make.top.equalTo(backgroundColorView).offset(7)

            make.right.equalTo(backgroundColorView).offset(-10)

            make.height.equalTo(16)
        }

        dayTimeLabel.snp.makeConstraints { make in

            make.left.right.equalTo(timinglabel)

            make.top.equalTo(timinglabel.snp.bottom).offset(3)

            make.height.equalTo(10)
        }

        headlineLabel.snp.makeConstraints { make in

            make.left.equalTo(iconImageView.snp.right).offset(4)

            make.right.equalTo(timinglabel.snp.left).offset(-2)

            make.top.equalTo(timinglabel)

            make.bottom.equalTo(dayTimeLabel)
        }

        lineView.snp.makeConstraints { make in

            make.top.equalTo(dayTimeLabel.snp.bottom).offset(3)

            make.left.equalTo(iconImageView)

            make.right.equalTo(dayTimeLabel)

            make.height.equalTo(2)
        }

        stankView.snp.makeConstraints { make in

            make.top.equalTo(lineView.snp.bottom).offset(8)

            make.left.equalTo(8)

            make.right.equalTo(lineView)

            make.bottom.equalTo(backgroundColorView).offset(-8)
        }
    }
}
